package com.smartmail.utility;

import android.graphics.Bitmap;
import android.graphics.Matrix;

public class AvatarCreator {
	private AvatarCreator(){
		
	}
	
	public static Bitmap createAvatar(int width, int height, Bitmap inputBitmap){
		    
		    int orgWidth = inputBitmap.getWidth();
	        int orgHeight = inputBitmap.getHeight();
	       
	        float scaleWidth = ((float) width) / orgWidth;
	        float scaleHeight = ((float) height) / orgHeight;
	       
	        Matrix matrix = new Matrix();
	  
	        if (scaleWidth > scaleHeight) matrix.postScale(scaleWidth, scaleWidth);
	        else matrix.postScale(scaleHeight, scaleHeight);
		    
		    Bitmap img = 
		    		Bitmap.createBitmap( 
		    				inputBitmap, 0, 0, 
		    				orgWidth, 
		    				orgHeight, matrix, false);
	
		    Bitmap finalImg = Bitmap.createBitmap( 
					img, 0, 0, 
					width, 
					height);
		    
		    return finalImg;
		}
}
